package com.tqjc.system.core.config;

import com.tqjc.system.common.constant.GlobalConstant;
import com.tqjc.system.core.util.RequestUtil;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.Map;

/**
 * @author 86195
 * @version 1.0
 * @description websocket配置
 * @date 2023/3/23 10:50
 */
public class WebSocketConfigurator extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Map<String, Object> userProperties = sec.getUserProperties();
        HttpServletRequest httpServletRequest = RequestUtil.getRequest();
        if(httpServletRequest != null){
            userProperties.put(GlobalConstant.STRING_IP,httpServletRequest.getRemoteHost());
        }
    }
}
